When one class makes up 1 % of your data, a model that predicts the majority class every single time scores 99 % accuracy and detects nothing. Chapter 4 addressed half of this problem by replacing accuracy with metrics that cannot be gamed this way. This chapter addresses the other half: changing the data rather than the metric.
We develop the oversampling family in order of sophistication. Random oversampling simply duplicates minority samples, which invites overfitting to the exact duplicated points; adding shrinkage jitters them apart. SMOTE synthesises genuinely new samples by interpolating between minority neighbours. Borderline-SMOTE concentrates that synthesis near the decision boundary, where it actually changes the classifier, and ADASYN goes further by generating more samples where the local neighbourhood is hardest to classify.
Oversampling is a data balancing technique that generates more samples of the minority class to address class imbalance.
In imbalanced datasets, the majority class can dominate the learning process, causing the model to bias towards it. Oversampling helps by:
Popular Oversampling Methods: The four methods listed below are developed in order in the next section, each one addressing a weakness of the one before it.
The simplest strategy to balance imbalance in a dataset is to randomly choose samples of the minority class and repeat or duplicate them, also called random oversampling with replacement.
Random oversampling can often lead to overfitting of the model since the generated synthetic observations get repeated, and the model sees the same observations again and again.
The shrinkage parameter in RandomOverSampler lets us perturb or shift each point by a small amount.
Shrinkage jitters the duplicated points but still adds no new information. SMOTE takes a different route and avoids duplication altogether, by creating genuinely new samples through interpolation between existing minority samples.
Where \(\lambda\) is a random number between 0 and 1.
SMOTE spreads the minority class over the region between existing minority samples, and this can increase the overlap between the two classes. The consequences are:
The overlap problem arises because plain SMOTE interpolates between all minority samples, including those deep inside the minority region where extra samples change nothing. Borderline-SMOTE is a variation that only generates synthetic samples from minority samples lying near the classification boundary.
The examples near the classification boundary are more prone to misclassification than those far away from the decision boundary. Producing more such minority samples along the boundary would help the model learn better about the minority class.
Borderline-SMOTE treats every borderline sample the same way. ADASYN refines this further by generating more synthetic samples where the local neighborhood is harder to classify, and fewer where it is already easy.
Let's work through a concrete SMOTE example:
Calculate the synthetic sample:
For x-coordinate:
For y-coordinate:
Result: New synthetic sample = (2.8, 3.8)
Consider a minority class sample with K=5 nearest neighbors:
Calculate hardness factor:
Interpretation: This sample has a hardness factor of 0.6, meaning it's relatively difficult to classify because it's surrounded by mostly majority class neighbors. It's likely near the classification boundary. ADASYN will generate more synthetic samples for this point compared to samples with lower hardness factors.
Given:
Task: Calculate the coordinates of the new synthetic sample using SMOTE.
Using the formula: \(x_{synthetic} = x_i + \lambda \cdot (x_{nn} - x_i)\)
For x-coordinate:
For y-coordinate:
Result: New synthetic sample = (2.5, 3.5)
Consider a minority class sample with K=7 nearest neighbors:
Tasks:
You have an imbalanced dataset with the following characteristics:
Task: Which oversampling method would you choose and why?
Recommended method: Borderline-SMOTE
Reasoning:
Alternative: ADASYN could also work well since it adapts to the hardness of each sample, but Borderline-SMOTE is more specifically designed for boundary-focused sampling.
Answer all 2 questions. Click an option for instant feedback.
Your score: 0 / 2